{
 "nbformat": 4,
 "nbformat_minor": 0,
 "metadata": {
  "colab": {
   "provenance": [],
   "toc_visible": true
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# Load Huggingface Model\n",
    "\n",
    "This code will use [Eland](https://) to load an embedding model into Elasticsearch\n",
    "\n",
    "\n",
    "Blog Vector Search (kNN) Implementation Guide - API Edition\n",
    "\n"
   ],
   "metadata": {
    "id": "sUmu4TerK9OG"
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "eaGnibZA-78Z"
   },
   "outputs": [],
   "source": [
    "!pip install -q elasticsearch eland[pytorch]"
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "import getpass"
   ],
   "metadata": {
    "id": "Fxius9__-9Mb"
   },
   "execution_count": 2,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Set Connection and Model information\n",
    "\n",
    "\n",
    "*   Cloud ID can be retrieved from the Elastic Cloud console\n",
    "*   Elastic API Key can be generated in Elasticsearch Kibana under Stack Management\n",
    "*   Model ID is the Model Card Name from Hugging Face\n",
    "\n"
   ],
   "metadata": {
    "id": "J3XJeDaJMMk9"
   }
  },
  {
   "cell_type": "code",
   "source": [
    "CLOUD_ID = getpass.getpass(\"Enter Elastic Cloud ID: \")\n",
    "ELASTIC_API = getpass.getpass(\"Enter Elastic API: \")\n",
    "MODEL_ID = getpass.getpass(\"Enter Model ID from Hugging Face Model Card \")"
   ],
   "metadata": {
    "id": "e_zGEcyr_Ce-"
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Load the model\n",
    "If you want to also start the model, uncomment the `--start` line"
   ],
   "metadata": {
    "id": "ZG6B0greNAQ7"
   }
  },
  {
   "cell_type": "code",
   "source": [
    "!eland_import_hub_model \\\n",
    "    --cloud-id $CLOUD_ID \\\n",
    "    --es-api-key $ELASTIC_API \\\n",
    "    --hub-model-id $MODEL_ID \\\n",
    "    --task-type text_embedding\n",
    "    # --start"
   ],
   "metadata": {
    "id": "oPKVhWeT_Cc4"
   },
   "execution_count": null,
   "outputs": []
  }
 ]
}